﻿Imports DevExpress.XtraBars

Public Class PlantillaPrincipal
    Dim c As New Controlador
    Public alta As Boolean

    Private Sub PlantillaPrincipal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comenzarprogressbar()
        f_login.MdiParent = Me
        Form1.MdiParent = Me
        f_stocks.MdiParent = Me
        f_usuarios.MdiParent = Me
        f_clientes.MdiParent = Me
        f_proveedores.MdiParent = Me
        f_productos.MdiParent = Me
        f_citas.MdiParent = Me
        f_mascotas.MdiParent = Me
        f_agenda.MdiParent = Me
        f_adopciones.MdiParent = Me
        f_informe.MdiParent = Me
        c.to_login()

        terminarprogressbar()

    End Sub


    Private Sub BarButtonItem31_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_clientes.ItemClick

        comenzarprogressbar()
        c.cerrar()

        f_clientes.Show()
        Me.deshabilitar()
        Me.b_alta_cli.Enabled = True
        Me.b_baja_cli.Enabled = True
        p_b_guardar.Enabled = True
        p_b_carnet.Enabled = True

        Me.b_modifica_cli.Enabled = True

        terminarprogressbar()
    End Sub

   
    Private Sub BarButtonItem42_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_salir.ItemClick
        comenzarprogressbar()
        If MsgBox("Esta seguro de salir de la aplicación", MsgBoxStyle.YesNo, "Salir") = MsgBoxResult.Yes Then
            Me.Close()
        End If
        terminarprogressbar()

    End Sub

 
    Private Sub b_cerrar_sesion_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_cerrar_sesion.ItemClick
        comenzarprogressbar()
        If MsgBox("Esta seguro de cerrar sesión", MsgBoxStyle.YesNo, "Cerrar Sesion") = MsgBoxResult.Yes Then
            c.cerrar()
            c.to_login()

        End If
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem6_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_usuarios.ItemClick
        comenzarprogressbar()

        c.cerrar()

        f_usuarios.Show()

        Me.deshabilitar()
        Me.b_alta_us.Enabled = True
        Me.b_baja_us.Enabled = True
        Me.b_modifica_us.Enabled = True
        p_guardar_usuarios.Enabled = True
        terminarprogressbar()

    End Sub


    Private Sub BarButtonItem12_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_baja_us.ItemClick
        comenzarprogressbar()
        c.baja_us()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem32_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_alta_cli.ItemClick
        comenzarprogressbar()
        f_clientes.alta_cli = True
        f_clientes.tb_nombre.Focus()
        c.limpiar_clientes()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem33_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_baja_cli.ItemClick
        comenzarprogressbar()
        c.baja_clientes()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem11_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_alta_us.ItemClick
        comenzarprogressbar()
        f_usuarios.alta_us = True
        f_usuarios.tb_nombre.Focus()
        c.limpiar_us()
        terminarprogressbar()
    End Sub

    Private Sub b_consultar_stocks_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_consultar_stocks.ItemClick
        comenzarprogressbar()
        c.cerrar()
        f_stocks.Show()
        Me.deshabilitar()
        Me.b_addUnidades.Enabled = True
        Me.restarUnidades.Enabled = True
        Me.p_generar.Enabled = True
        terminarprogressbar()


    End Sub

  
    Private Sub BarButtonItem25_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_alta_prov.ItemClick
        comenzarprogressbar()
        f_proveedores.alta_pro = True
        f_proveedores.tb_nombre.Focus()
        c.limpiar_proveedores()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem26_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_baja_prov.ItemClick
        comenzarprogressbar()
        c.baja_proveedores()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem24_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_proveedores.ItemClick
        comenzarprogressbar()
        c.cerrar()

        f_proveedores.Show()

        Me.deshabilitar()
        Me.b_alta_prov.Enabled = True
        Me.b_baja_prov.Enabled = True
        Me.b_modifica_prov.Enabled = True
        p_guardar_proveedores.Enabled = True
        terminarprogressbar()


    End Sub

    Private Sub BarButtonItem7_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_productos.ItemClick
        comenzarprogressbar()
        c.cerrar()
        f_productos.Show()

        Me.deshabilitar()
        p_guardar_productos.Enabled = True
        Me.b_alta_prod.Enabled = True
        Me.b_baja_prod.Enabled = True
        Me.b_modifica_prod.Enabled = True
        terminarprogressbar()

    End Sub

    Private Sub BarButtonItem14_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_alta_prod.ItemClick
        comenzarprogressbar()
        f_productos.alta_producto = True
        f_productos.tb_nombre.Focus()
        c.limpiar_productos()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem15_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_baja_prod.ItemClick
        comenzarprogressbar()
        c.baja_productos()
        terminarprogressbar()
    End Sub

    Private Sub b_addUnidades_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_addUnidades.ItemClick
        comenzarprogressbar()
        f_pop_unidades.Show()
        f_pop_unidades.a = True
        terminarprogressbar()
    End Sub

    Private Sub restarUnidades_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles restarUnidades.ItemClick
        comenzarprogressbar()
        f_pop_unidades.Show()
        f_pop_unidades.a = False
        terminarprogressbar()
    End Sub

    Private Sub p_consultarcita_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_consultarcita.ItemClick
        comenzarprogressbar()
        c.cerrar()
        f_citas.Show()
        Me.deshabilitar()
        Me.p_cita.Enabled = True
        Me.b_agregar_cita.Enabled = True
        Me.b_eliminar_cita.Enabled = True
        Me.b_modificar_cita.Enabled = True
        BarButtonItem5.Enabled = True
        Me.p_guardar.Enabled = True
        p_citas_dia.Enabled = True
        terminarprogressbar()

    End Sub
    Public Sub deshabilitar()

        p_guardar_proveedores.Enabled = False
        p_citas_dia.Enabled = False
        Me.p_guardar.Enabled = False
        b_modificar_cita.Enabled = False
        p_cita.Enabled = False
        b_eliminar_cita.Enabled = False
        b_agregar_cita.Enabled = False
        p_guardar_productos.Enabled = False
        b_addUnidades.Enabled = False
        restarUnidades.Enabled = False
        b_alta_cli.Enabled = False
        b_baja_cli.Enabled = False
        b_modifica_cli.Enabled = False
        b_alta_mascotas.Enabled = False
        Me.p_generar.Enabled = False
        p_historial_mascota.Enabled = False
        p_guardar_mascota.Enabled = False
        b_modif_mascota.Enabled = False
        b_baja_mascotas.Enabled = False
        p_adopcion_nueva.Enabled = False
        pg_b_generar.Enabled = False
        b_alta_us.Enabled = False
        p_b_guardar.Enabled = False
        p_b_carnet.Enabled = False
        p_adopcion_nueva.Enabled = False

        b_baja_us.Enabled = False
        b_modifica_us.Enabled = False
        b_alta_prov.Enabled = False
        b_baja_prov.Enabled = False
        b_modifica_prov.Enabled = False
        b_alta_prod.Enabled = False
        b_baja_prod.Enabled = False
        b_modifica_prod.Enabled = False
        p_guardar_usuarios.Enabled = False
        BarButtonItem5.Enabled = False
        b_alta_mascotas.Enabled = False
        b_baja_mascotas.Enabled = False
        b_modif_mascota.Enabled = False
        p_guardar_mascota.Enabled = False
        p_historial_mascota.Enabled = False
    End Sub
 
    Private Sub b_agregar_cita_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_agregar_cita.ItemClick
        comenzarprogressbar()
        If f_citas.gb_datos.Visible = False Then

            f_citas.gb_datos.Visible = True
            f_citas.SplitContainer1.Panel1Collapsed = False
            Me.b_modificar_cita.Enabled = False
            Me.b_eliminar_cita.Enabled = False
            Me.p_cita.Enabled = False
            Me.p_guardar.Enabled = True
            alta = True
            f_citas.tb_cliente.Visible = True
            f_citas.Label3.Visible = True

        Else
            f_citas.gb_datos.Visible = False
            Me.b_modificar_cita.Enabled = True
            Me.b_eliminar_cita.Enabled = True
            Me.p_guardar.Enabled = False
            Me.p_cita.Enabled = True
            If f_citas.gb_busqueda.Visible = False Then
                f_citas.SplitContainer1.Panel1Collapsed = True

            End If
        End If
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem6_ItemClick_1(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem6.ItemClick
        comenzarprogressbar()
        Help.ShowHelp(Me, HelpProvider1.HelpNamespace)

        terminarprogressbar()

    End Sub

    Private Sub n_Protozoo_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles n_Protozoo.MouseDoubleClick
        comenzarprogressbar()
        Show()
        WindowState = FormWindowState.Maximized
        Activate()
        terminarprogressbar()
    End Sub

    Private Sub b_alta_mascotas_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_alta_mascotas.ItemClick
        comenzarprogressbar()
        f_mascotas.alta_mascota = True
        f_mascotas.tb_nombre.Focus()
        c.limpiar_mascotas()
        terminarprogressbar()
    End Sub

    Private Sub p_mascotas_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_mascotas.ItemClick
        comenzarprogressbar()
        c.cerrar()
        f_mascotas.Show()
        Me.deshabilitar()
        p_historial_mascota.Enabled = True
        p_guardar_mascota.Enabled = True
        Me.b_alta_mascotas.Enabled = True
        Me.b_baja_mascotas.Enabled = True
        Me.b_modif_mascota.Enabled = True
        terminarprogressbar()
    End Sub

    Private Sub b_baja_mascotas_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_baja_mascotas.ItemClick
        comenzarprogressbar()
        c.baja_mascotas()
        terminarprogressbar()
    End Sub

 

    Private Sub p_agenda_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_agenda.ItemClick
        comenzarprogressbar()
        c.cerrar()
        Me.deshabilitar()

        f_agenda.Show()
        terminarprogressbar()
    End Sub

    Private Sub p_cita_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_cita.ItemClick
        comenzarprogressbar()
        c.confirmar_cita()
        terminarprogressbar()

    End Sub

    Private Sub BarButtonItem5_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem5.ItemClick

        comenzarprogressbar()
        If f_citas.gb_busqueda.Visible = False Then
            f_citas.gb_busqueda.Visible = True
            f_citas.SplitContainer1.Panel1Collapsed = False
        Else
            f_citas.gb_busqueda.Visible = False
            If f_citas.gb_datos.Visible = False Then
                f_citas.SplitContainer1.Panel1Collapsed = True

            End If
        End If
        terminarprogressbar()

    End Sub

    Private Sub b_modificar_cita_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_modificar_cita.ItemClick
        comenzarprogressbar()
        If f_citas.gb_datos.Visible = False Then
            f_citas.gb_datos.Visible = True
            Me.b_agregar_cita.Enabled = False
            Me.b_eliminar_cita.Enabled = False
            Me.p_guardar.Enabled = True
            Me.p_cita.Enabled = False
            f_citas.SplitContainer1.Panel1Collapsed = False
            alta = False

            f_citas.cb_mascota.Enabled = False
            f_citas.tb_cliente.Visible = False
            f_citas.Label3.Visible = False

            f_citas.cb_mascota.Items.Add(f_citas.dg_citas.CurrentRow.Cells("nombre").Value)
            f_citas.cb_mascota.SelectedItem = (f_citas.dg_citas.CurrentRow.Cells("nombre").Value)
            f_citas.cb_consulta.SelectedItem = f_citas.dg_citas.CurrentRow.Cells("servicio").Value
            f_citas.cb_empleado.SelectedItem = f_citas.dg_citas.CurrentRow.Cells("veterinario").Value
            f_citas.cb_hora.SelectedItem = (f_citas.dg_citas.CurrentRow.Cells("hora").Value)

            f_citas.calendario.SetDate(f_citas.dg_citas.CurrentRow.Cells("fecha").Value)



            f_citas.dg_citas.Enabled = False

        Else
            f_citas.gb_datos.Visible = False
            Me.b_agregar_cita.Enabled = True
            Me.b_eliminar_cita.Enabled = True
            Me.p_cita.Enabled = True
            Me.p_guardar.Enabled = False
            f_citas.dg_citas.Enabled = True
            If f_citas.gb_busqueda.Visible = False Then
                f_citas.SplitContainer1.Panel1Collapsed = True

            End If
        End If
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem7_ItemClick_1(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_guardar.ItemClick
        comenzarprogressbar()
        If alta Then
            c.alta_cita()
        Else
            c.modificar_cita()
        End If
        terminarprogressbar()
    End Sub

    Private Sub b_eliminar_cita_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_eliminar_cita.ItemClick
        comenzarprogressbar()
        If MsgBox("Seguro que deseas eliminar este elemento", MsgBoxStyle.OkCancel, "Aviso") = MsgBoxResult.Ok Then
            c.eliminar_cita()
        End If
        terminarprogressbar()
    End Sub

    Private Sub inicio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles inicio.Click

    End Sub

    Private Sub p_adopcion_nueva_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_adopcion_nueva.ItemClick
        comenzarprogressbar()
        c.adoptar()
        terminarprogressbar()
    End Sub

    Private Sub p_adop_disponibles_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_adop_disponibles.ItemClick
        comenzarprogressbar()
        c.cerrar()

        f_adopciones.Show()
        Me.deshabilitar()

        p_adopcion_nueva.Enabled = True

        terminarprogressbar()
    End Sub

    Private Sub p_citas_dia_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_citas_dia.ItemClick
        comenzarprogressbar()
        f_informe.Close()
        f_informe.MdiParent = Me

        f_informe.rdInforme = New r_citas

        f_informe.Show()
        terminarprogressbar()

    End Sub

    Private Sub BarButtonItem7_ItemClick_2(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_generar.ItemClick
        comenzarprogressbar()
        c.generarInformeStock()
        terminarprogressbar()

    End Sub

    Private Sub BarButtonItem11_ItemClick_1(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_historial_mascota.ItemClick

        comenzarprogressbar()
        c.generarInformeHistorial()
        terminarprogressbar()


    End Sub

    Private Sub BarButtonItem12_ItemClick_1(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_guardar_usuarios.ItemClick
        comenzarprogressbar()
        c.guardar_f_usuarios()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem14_ItemClick_1(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_guardar_productos.ItemClick
        comenzarprogressbar()
        c.guardar_f_productos()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem13_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_guardar_proveedores.ItemClick
        comenzarprogressbar()
        c.guardar_f_proveedores()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem16_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_guardar_mascota.ItemClick
        comenzarprogressbar()
        c.guardar_f_mascotas()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem15_ItemClick_1(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_b_guardar.ItemClick
        comenzarprogressbar()
        c.guardar_f_clientes()
        terminarprogressbar()
    End Sub

    Private Sub BarButtonItem18_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles p_b_carnet.ItemClick
        comenzarprogressbar()
        AddHandler f_clientes.PrintDocument1.PrintPage, AddressOf c.imprimir

        f_clientes.PrintDocument1.Print()
        terminarprogressbar()
    End Sub
    Public Sub comenzarprogressbar()
        ProgressBar1.Visible = True
        ProgressBar1.MarqueeAnimationSpeed = 5
    End Sub
    Public Sub terminarprogressbar()
        ProgressBar1.Visible = False
        ProgressBar1.MarqueeAnimationSpeed = 0
    End Sub

    Private Sub b_modifica_us_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_modifica_us.ItemClick
        comenzarprogressbar()
        c.guardar_f_usuarios()
        terminarprogressbar()
    End Sub

    Private Sub b_modifica_prov_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_modifica_prov.ItemClick
        comenzarprogressbar()
        c.guardar_f_proveedores()
        terminarprogressbar()
    End Sub

    Private Sub b_modifica_prod_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_modifica_prod.ItemClick
        comenzarprogressbar()
        c.guardar_f_productos()
        terminarprogressbar()
    End Sub

    Private Sub b_modifica_cli_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_modifica_cli.ItemClick
        comenzarprogressbar()
        c.guardar_f_clientes()
        terminarprogressbar()
    End Sub

    Private Sub b_modif_mascota_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles b_modif_mascota.ItemClick
        comenzarprogressbar()
        c.guardar_f_mascotas()
        terminarprogressbar()
    End Sub

    
    Private Sub BarButtonItem7_ItemClick_3(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem7.ItemClick
        System.Diagnostics.Process.Start("www.google.es")
    End Sub

    Private Sub BarButtonItem11_ItemClick_2(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem11.ItemClick
        System.Diagnostics.Process.Start("www.mundo-mascota.com")
    End Sub

    Private Sub BarButtonItem12_ItemClick_2(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem12.ItemClick
        System.Diagnostics.Process.Start("http://es.wikipedia.org/wiki/Protozoo")
    End Sub

    Private Sub BarButtonItem13_ItemClick_1(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem13.ItemClick
        System.Diagnostics.Process.Start("about:blank")
    End Sub
End Class

